/**
* This source code shows how to use the webcam or external cameras 
* and capture frames from them in OpenCV. One thing to notice is 
* that this method does not support DirectShow cameras.
*
* The author, David Qiu, designs this method and implements it in
* OpenCV. The author remains all rights of the methods, algorithms,
* and code. One can only access to the code for study purpose.
* Commercial use or releasement related to the methods, algorithms,
* or code is NOT allowed.
*
* Creative Commons: BY-NC-ND
*
* Author:  David Qiu (david@davidqiu.com)
* Website: http://www.davidqiu.com/
*/

#ifndef _WEBCAMCAPTURE_HPP_
#define _WEBCAMCAPTURE_HPP_

#include <opencv.hpp>

int WebcamCapture(int argc, char** argv)
{
  IplImage* frame = NULL;

  // Connect to the webcam
  CvCapture* webcam = cvCaptureFromCAM(-1);

  // Loop show the video stream
  while (1)
  {
  // Obtain a new frame from the camera
  frame = cvQueryFrame(webcam);

  // Check if receipt successful
  if (!frame) break;

  // Show the image obtained
  cvShowImage("webcam", frame);

  // Manual exit
  char key = cvWaitKey(20);
  if (key == 27) break;
  }

  // Release resources
  cvReleaseCapture(&webcam);

  // Program exit
  return 0;
}

#endif //_WEBCAMCAPTURE_HPP_
